﻿
function addBookmark(title, url) { var a = title || this.location.href; var b = url || document.title; var c = window.sidebar; if (c && !!c.addPanel) { c.addPanel(a, b, "") } else if (document.all) { window.external.AddFavorite(b, a) } else { alert('请按 Ctrl + D 为你的浏览器添加书签！') } }

function setHomePage(obj, url) { url = url || window.location.href; try { obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(url) } catch (e) { if (window.netscape) { try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect") } catch (e) { alert("此操作被浏览器拒绝n请在浏览器地址栏输入“about:config”并回车\n然后将signed.applets.codebase_principal_support]的值设置为'true',双击即可。") } var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); prefs.setCharPref('browser.startup.homepage', url) } } }


function RenderFusionChartHtml(type, data, id, width, height, aligntype) {
    if (data == null || data == '') {
        return "";
    }
    if (id == null) {
        id = parseInt(999999 * Math.random());
    }
    var ret = " <div id=\"_FusionChart_Div_" + id + "\" align=\"" + aligntype + "\"></div>\n";
    ret += "<script type=\"text/javascript\">\n";

    ret += "var _FusionChart_" + id + " = new FusionCharts(\"http://i.ssimg.cn/images/quote2011/stockinfo/Charts_full_3_2/" + type + ".swf\",\"FusionChart_Swf_" + id + "\", \"" + width + "\", \"" + height + "\",\"0\",\"0\");\n";
    ret += "_FusionChart_" + id + ".setDataXML(\"" + data + "\");\n";
    ret += "_FusionChart_" + id + ".render(\"_FusionChart_Div_" + id + "\");</script>\n";

    return ret;
}
$(document).ready(function () {
    var requestCode = document.getElementById("RequestCode").value;
    document.getElementById(requestCode).className = "leftmenu_on";
    document.getElementById(requestCode).style.backgroundColor = "#eff3fc";
    var pageType = $("#pagetype").val();
    if (pageType == "Tab") {
        $("#datanav li a").first().click();
    } else if (pageType == "Select") {
        oChange();
    } else {
        simplePageOnload();
    }
});
function AddFavorite(sURL, sTitle) {
    try { window.external.addFavorite(sURL, sTitle); }
    catch (e) {
        try { window.sidebar.addPanel(sTitle, sURL, ""); }
        catch (e) { alert("加入收藏失败，请使用Ctrl+D进行添加"); }
    }
}
function SetHome(obj, vrl) {
    try { obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl); }
    catch (e) {
        if (window.netscape) {
            try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); }
            catch (e) { alert("此操作被浏览器拒绝！请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为'true'"); }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', vrl);
        }
    }
}
var currentDiv = "";
function slctdDataTag(showContent, selfObj) {
    $("#FlashImage_History").html();
    var tag = document.getElementById("datanav").getElementsByTagName("li");
    var taglength = tag.length;
    for (i = 0; i < taglength; i++) {
        tag[i].className = "";
    }
    selfObj.parentNode.className = "curnav";
    if (currentDiv != selfObj.id) {
        currentDiv = selfObj.id;
        var title = $("#" + currentDiv).text();
        doAjaxRequest(currentDiv, $("#" + currentDiv).attr("priceColumn"), title);
    }
}
String.prototype.endWith = function (s) {
    if (s == null || s == "" || this.length == 0 || s.length > this.length)
        return false;
    if (this.substring(this.length - s.length) == s)
        return true;
    else
        return false;
    return true;
}
String.prototype.startWith = function (s) {
    if (s == null || s == "" || this.length == 0 || s.length > this.length)
        return false;
    if (this.substr(0, s.length) == s)
        return true;
    else
        return false;
    return true;
}
function correctDate(dataString) {
    var pageCode = $("#RequestCode").val();
    if (pageCode == "GFJQ" || pageCode == "YM" || pageCode == "DD" || pageCode == "ZXD" || pageCode == "WXD" || pageCode == "YD" || pageCode == "HXM" || pageCode == "BXM" || pageCode == "HHM" || pageCode == "QSHYD" || pageCode == "GHYYDL" || pageCode == "CXJMSHYD" || pageCode == "DXYW" || pageCode == "YZYW" || pageCode == "TXYW" || pageCode == "GYSYYH" || pageCode == "GFZSYYH" || pageCode == "CSSYYH" || pageCode == "YHYJRJG" || pageCode == "QTLJRJG" || pageCode == "SPFJYSJ") {
        dataString = dataString.replace("-", "年");
        dataString = dataString.replace("-", "月");
        dataString = dataString.substr(0, dataString.indexOf("月") + 1);
    }
    if (pageCode == "NLMY") {
        dataString = dataString.replace("-", "年");
        dataString = dataString.replace("-", "季度");
        dataString = dataString.substr(0, dataString.indexOf("季度") + 2);
    }
    return dataString;
}
function doAjaxRequest(code, priceColumns, title) {
    var _tableName = document.getElementById("table").value;
    var _filters = document.getElementById("filters").value;
    var _pricecolumns = priceColumns;
    var _orderby = document.getElementById("datecolumn").value;
    if (title != "") {
        $("#smalltitle").html(title + "近期数据");
    }
    if (title.indexOf("银行总负债") >= 0) {
        $("#rowname0").html("总负债(亿元)");
        $("#rowname1").html("总负债同比(%)");
        $("#rowname2").html("总负债占银行业金融机构比例(%)");
    }
    if (title.indexOf("银行总资产") >= 0) {
        $("#rowname0").html("总资产(亿元)");
        $("#rowname1").html("总资产同比(%)");
        $("#rowname2").html("总资产占银行业金融机构比例(%)");
    }
    if (!code.startWith('_')) {
        if (code != "") {
            var dengHaoIndex = _filters.lastIndexOf("=");
            _filters = _filters.substr(0, dengHaoIndex + 1);
            _filters += code;
        }
    }
    if (_filters != "") {
        $.ajax({
            type: 'get',
            url: 'ajax/GetData.ashx',
            data: "tablename=" + _tableName + "&filters=" + _filters + "&pricecolumns=" + _pricecolumns + "&orderby=" + _orderby,
            success: function (json) {
                callback(json);
            }
        });
    } else {
        $.ajax({
            type: 'get',
            url: 'ajax/GetData.ashx',
            data: "tablename=" + _tableName + "&pricecolumns=" + _pricecolumns + "&orderby=" + _orderby,
            success: function (json) {
                callback(json);
            }
        });
    }
}
var tbody = "";
function callback(msg) {
    var pagetype = $("#pagetype").val();
    var title = "";
    if (pagetype == "Simple") {
        title = $("#simpletitle").val();
    } else if (pagetype == "Tab") {
        title = $("#" + currentDiv).text() + $("#pageunit").val();
    } else {
        title = $("#select").find("option:selected").text() + $("#pageunit").val();
    }
    if (msg == "") {
        var html = $("#currentTable").html();
        if (html.indexOf("暂无数据") < 0) {
            tbody = html;
        }
        $("#currentTable").empty();
        $("#currentTable").append("<tr><td>暂无数据</td></tr>");
    } else {
        if (tbody != "") {
            $("#currentTable").html(tbody);
        }
        var json = eval('(' + msg + ')');
        var prices = new Array(json.Prices.length);
        for (i = 0; i < prices.length; i++) {
            var dataarray = json.Prices[i].PriceList.split(",");
            var array = new Array(dataarray.length + 1);
            array[0] = json.Prices[i].EDATE;
            for (j = 0; j < dataarray.length; j++) {
                array[j + 1] = dataarray[j];
            }

            prices[i] = array;
        }

        var pageCode = $("#RequestCode").val();
        for (i = prices.length - 5; i < prices.length; i++) {
            for (j = 0; j < prices[0].length; j++) {
                var index = i - prices.length + 5;
                if (j == 1) {
                    $("#r" + j + "c" + index).text(changvs(prices[i][j]));
                } else if (j == 0) {
                    var _dateString2 = getDataString(prices[i][j]);
                    $("#r" + j + "c" + index).text(_dateString2);
                } else {
                    $("#r" + j + "c" + index).text(changvs(prices[i][j]));
                }
                $("#r" + j + "c" + index).removeClass("font_color_red");
                $("#r" + j + "c" + index).removeClass("font_color_green");
                if (j != 0) {
                    var tongbi = tongbihuanbi();
                    if (tongbi == 0) {
                        if (Number(prices[i][1]) > Number(prices[i - 1][1])) {
                            $("#r" + j + "c" + index).addClass("font_color_red");
                        } else if (Number(prices[i][1]) < Number(prices[i - 1][1])) {
                            $("#r" + j + "c" + index).addClass("font_color_green");
                        }
                    } else if (tongbi == 1 || tongbi == 2) {
                        if (j == 1) {
                            if (Number(prices[i][1]) > Number(prices[i - 1][1])) {
                                $("#r" + j + "c" + index).addClass("font_color_red");
                            } else if (Number(prices[i][1]) < Number(prices[i - 1][1])) {
                                $("#r" + j + "c" + index).addClass("font_color_green");
                            }
                        }
                    } else if (tongbi == 4) {
                        if (j == 1 || j == 4 || j == 7 || j == 10 || j == 13 || j == 16 || j == 19) {
                            if (Number(prices[i][1]) > Number(prices[i - 1][1])) {
                                $("#r" + j + "c" + index).addClass("font_color_red");
                            } else if (Number(prices[i][1]) < Number(prices[i - 1][1])) {
                                $("#r" + j + "c" + index).addClass("font_color_green");
                            }
                        }
                    }
                }
            }
        }
        dreawMSLine(prices, "", title);
    }
}
function tongbihuanbi() {
    var pageCode = $("#RequestCode").val();
    var tongbi = 0;
    if (pageCode == "GYSYYH" || pageCode == "GFZSYYH" || pageCode == "CSSYYH" || pageCode == "YHYJRJG" || pageCode == "QTLJRJG") {
        tongbi = 1;
    }
    if (pageCode == "DXYW" || pageCode == "YZYW" || pageCode == "TXYW" || pageCode == "QSHYD" || pageCode == "GHYYDL" || pageCode == "CXJMSHYD") {
        tongbi = 2;
    }
    if (pageCode == "ZZSSJG" || pageCode == "SPFJYSJ") {
        tongbi = 3;
    }
    return tongbi;
}
function getUnit() {
    return "";
}
function changvs(num) {
    var needchange = true;
    var s = num;
    var absValue = 0;
    if (Number(s) < 0) {
        s = Math.abs(s);
        absValue = 1;
    }
    if (needchange) {
        var s = s.toString().split(",").join("");
        if (/[^0-9\.]/.test(s)) return "invalid value";
        s = s.replace(/^(\d*)$/, "$1.");
        s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1");
        s = s.replace(".", ",");
        var re = /(\d)(\d{3},)/;
        while (re.test(s))
            s = s.replace(re, "$1,$2");
        s = s.replace(/,(\d\d)$/, ".$1");
        s = s.replace(/^\./, "0.");
        if (absValue == 1) {
            return "-" + s;
        } else {
            return s;
        }
    } else {
        return s;
    }
}
function simplePageOnload() {
    var priceColumn = $("#priceColumn").val();
    var code = $("#priceColumn").attr("code");
    doAjaxRequest(code, priceColumn, "");
}
function oChange() {
    $("#FlashImage_History").html();
    var checkValue = $("#select").find("option:selected").attr("priceColumn");
    var code = $("#select").find("option:selected").attr("code");
    var name = $("#select").find("option:selected").text();
    doAjaxRequest(code, checkValue, name);
}
function inArray(needle, array) {
    var len = array.length;
    for (var i = 0; i < len; i++) {
        if (needle === array[i].YearMonth) {
            return true;
        }
    }
    return false;
}
var flashcount = 0;
function dreawMSLine(array, unit, title) {
    var maxValue = -100000;
    var minValue = 100000;
    for (i = array.length - 1; i >= 0; i--) {
        var _arraydatastring = array[i][0];
        _arraydatastring = _arraydatastring.substr(0, _arraydatastring.lastIndexOf("-"))
        var _value = array[i][1];
        if (Number(_value) > Number(maxValue)) {
            maxValue = _value;
        }
        if (Number(_value) < Number(minValue)) {
            minValue = _value;
        }
    }
    maxValue = Number(maxValue) + (Number(maxValue) - Number(minValue)) * 0.1;
    minValue = Number(minValue) - (Number(maxValue) - Number(minValue)) * 0.1;
    var data = "";
    data = "<chart showLimits='0' caption='" + title + "' labelStep='" + skipPoint() + "' borderColor='ffffff' labelDisplay='WRAP' yAxisMinValue='" + minValue + "' yAxisMaxValue='" + maxValue + "'  formatNumber='1' formatNumberScale='0' showToolTip='1' toolTipBgColor='d8d8d8'  baseFont='宋体' numVDivLines='50' adjustDiv='0' numDivLines='4' baseFontSize='12' showvalues='0' divLineColor='d8d8d8' showAboutMenuItem='0' bgColor='ffffff' connectNullData='1' canvasPadding='4' canvasBorderColor='6eaddf' canvasBorderThickness='2'>";
    data += "<categories>";
    var vcount = 0;
    for (var i = 0; i < array.length; i++) {
        var _datastring = getDataString(array[i][0]);
        var exist = false;
        var tempstring = correctDate(_datastring);
        if (tempstring.indexOf("-") > 0) {
            tempstring = tempstring.replace("-", "年");
            tempstring = tempstring.replace("-", "月");
            tempstring = tempstring.substr(0, tempstring.indexOf("月") + 1);
        }
        if (i == 0) {
            data += "<category label='" + tempstring + "' showLabels='0'/>";
        } else {
            data += "<category label='" + tempstring + "' showLabels='1'/>";
        }
    }
    data += "</categories>"
    data += "<dataset>";
    for (var i = 0; i < array.length; i++) {
        var _dateString = getDataString(array[i][0]);
        if (unit == "指数") {
            unit = "";
        }

        if (couldSeePoint(i)) {
            data += "<set value='" + Math.round(array[i][1]) + "' toolText='" + _dateString + "," + array[i][1] + unit + "' anchorAlpha='100' />";
        } else {
            data += "<set value='" + Math.round(array[i][1]) + "' toolText='" + _dateString + "," + array[i][1] + unit + "' anchorAlpha='0' />";
        }
    }
    data += "</dataset>";
    data += "</chart>";
    var xml = RenderFusionChartHtml('MSLine', data, 1, 650, 300, 'center');
    $("#FlashImage_History").append("<div id=\"flashdiv" + flashcount + "\"></div>")
    $("#flashdiv" + flashcount).html(xml);
    flashcount = flashcount + 1;
}
function couldSeePoint(count) {
    var temp = 40;
    var pageCode = $("#RequestCode").val();
    if (pageCode == "GFJQ" || pageCode == "YM" || pageCode == "DD" || pageCode == "ZXD" || pageCode == "WXD" || pageCode == "YD" || pageCode == "HXM" || pageCode == "BXM" || pageCode == "HHM" || pageCode == "QSHYD" || pageCode == "GHYYDL" || pageCode == "CXJMSHYD" || pageCode == "DXYW" || pageCode == "YZYW" || pageCode == "TXYW" || pageCode == "GYSYYH" || pageCode == "GFZSYYH" || pageCode == "CSSYYH" || pageCode == "YHYJRJG" || pageCode == "QTLJRJG") {
        temp = 32;
    } else if (pageCode == "NLMY") {
        temp = 20;
    }
    if (count % Number(temp) == 0) {
        return true;
    } else {
        return false;
    }
}
function skipPoint() {
    var temp = 40;
    var pageCode = $("#RequestCode").val();
    if (pageCode == "GFJQ" || pageCode == "YM" || pageCode == "DD" || pageCode == "ZXD" || pageCode == "WXD" || pageCode == "YD" || pageCode == "HXM" || pageCode == "BXM" || pageCode == "HHM" || pageCode == "QSHYD" || pageCode == "GHYYDL" || pageCode == "CXJMSHYD" || pageCode == "DXYW" || pageCode == "YZYW" || pageCode == "TXYW" || pageCode == "GYSYYH" || pageCode == "GFZSYYH" || pageCode == "CSSYYH" || pageCode == "YHYJRJG" || pageCode == "QTLJRJG") {
        temp = 32;
    } else if (pageCode == "NLMY") {
        temp = 20;
    }
    return temp;
}
function getDataString(dataString) {
    var _dateString = dataString.substr(0, dataString.indexOf(" "));
    return correctDate(_dateString);
}



var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA-15599747-1']);

_gaq.push(['_setDomainName', '.stockstar.com']);

_gaq.push(['_setAllowHash', false]);

_gaq.push(['_trackPageview']);

(function () {

    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

})();